<template>
	<view class="cart-comtatiner" v-if="cart.length !== 0">
		<!-- 收货地址 -->
		<my-address></my-address>
		<!-- 商品列表标题 -->
		<view class="card-title">
			<!-- 左侧图标 -->
			<uni-icons type="shop" size="24"></uni-icons>
			<!-- 右侧文字 -->
			<text class="card-text"> 购物车</text>
		</view>
		
		<!-- 商品列表区 -->
		<uni-swipe-action>
			
			<block v-for="(item,i) in cart" :key="i">
				<uni-swipe-action-item :right-options="options" @click="bindClick(item)">
					<my-goods :item="item" :showRadio="true" :showNumber="true"
				 @radioChange="radioChange"
				 @numberChange="numberChangeHandle"
				 ></my-goods>
				</uni-swipe-action-item>
				
			</block>
		</uni-swipe-action>
		
		<!-- 结算 -->
		<my-settle></my-settle>
	</view>
	
	<view class="empty-cart" v-else>
		<uni-icons type="cart" size="28"></uni-icons>
		暂无商品
	</view>
</template>

<script>
	import tabBar from '@/mixins/tarbar.js'
	import { mapState,mapMutations } from 'vuex'
	
	export default {
		mixins:[tabBar],
		computed:{
			...mapState('m_cart',['cart'])
		},
		data() {
			return {
				options:[
				        {
				            text: '删除',
				            style: {
				                backgroundColor: '#dd524d'
				            }
				        }
				      ]

			};
		},
		onShow() {
			
		},
		methods:{
			...mapMutations('m_cart',['updateGoodsState','updateGoodsCount','removeGoods']),
			radioChange(e){
				this.updateGoodsState(e)
			},
			numberChangeHandle(e){
				this.updateGoodsCount(e)
			},
			bindClick(item){
				this.removeGoods(item.goods_id)
			}
		}
	}
</script>

<style lang="scss" scoped>

.card-title{
	height: 80rpx;
	display: flex;
	align-items: center;
	border-bottom: 2rpx solid #efefef;
	padding-left: 10rpx;
	.card-text{
		font-size: 28rpx;
		margin-left: 10rpx;
	}
}
.empty-cart{
	width: 100vw;
	height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
}

</style>
